package com.zxm.sunshineaiary.view.mydialog;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.GridView;

import com.zxm.sunshineaiary.activity.R;
import com.zxm.sunshineaiary.adapter.WeatherAdapter;

public class WeatherDialog extends Dialog {

	private static WeatherDialog instance = null;
	private Context mContext = null;
	private GridView mGridView = null;
	private WeatherAdapter mSimpleAdapter = null;
	private ArrayList<HashMap<String, Object>> mArrayList = null;

	public static WeatherDialog getWeatherDialog(Context context) {
		if (null == instance) {
			instance = new WeatherDialog(context);
		}
		return instance;
	}

	public WeatherDialog(Context context, int theme) {
		super(context, theme);
		mContext = context;

	}

	protected WeatherDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		mContext = context;
	}

	public WeatherDialog(Context context) {
		super(context, R.style.TANCStyle);
		mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.weatherdialog);
		findView();
		init(mContext);
		setAdapter(mContext);
	}

	private void findView() {
		mGridView = (GridView) findViewById(R.id.weatherdialog_gridView);
	}

	private void init(Context context) {
		mArrayList = new ArrayList<HashMap<String, Object>>();
		this.setCanceledOnTouchOutside(true);
		WindowManager.LayoutParams params = this.getWindow().getAttributes();
		params.width = WindowManager.LayoutParams.FILL_PARENT;
		params.height = WindowManager.LayoutParams.WRAP_CONTENT;
		this.getWindow().setAttributes(params);
	}

	private void setAdapter(Context context) {
		mSimpleAdapter = new WeatherAdapter(context);
		mGridView.setAdapter(mSimpleAdapter);
	}
}
